package 周赛;

import javax.swing.*;
import java.util.*;
import java.util.stream.Collectors;

public class 至少在两个数组中出现的值 {

    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        List<Integer> list = new ArrayList<>();
        Set<Integer> set1 = toSet(nums1);
        Set<Integer> set2 = toSet(nums2);
        Set<Integer> set3 = toSet(nums3);
        System.out.println(set1.size());
        System.out.println(set2.size());
        System.out.println(set3.size());
        for (int i = 0; i < nums1.length; i++) {
            if ((set2.contains(nums1[i]) || set3.contains(nums1[i])) && !list.contains(nums1[i])){
                list.add(nums1[i]);
            }
        }
        for (int i = 0; i < nums2.length; i++) {
            if ((set1.contains(nums2[i]) || set3.contains(nums2[i])) && !list.contains(nums2[i])){
               list.add(nums2[i]);
            }
        }
        for (int i = 0; i < nums3.length; i++) {
            if ((set1.contains(nums3[i]) || set2.contains(nums3[i])) && !list.contains(nums3[i]))
                list.add(nums3[i]);
        }
        return list;
    }
    public Set<Integer> toSet(int[] nums){
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            set.add(nums[i]);
        }
        return set;
    }
}
